home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUTORC.ZIP / TUT2.C < prev    next >
C/C++ Source or Header  |  1994-10-30  |  7KB  |  225 lines

  1. /*
  2.   tut2.c
  3.   10/30/94
  4.   from tutprog2.pas
  5.   Adapted from Denthor's tutprog2.pas
  6.   Translated into C, from Denthor's VGA Trainer, by
  7.   Steve Pinault, scp@ohm.att.com
  8.   Compiled with Microsoft Visual C++ 1.5 (Microsoft C 8.0)
  9.   To compile:
  10.   First compile the subroutines in tutsubs.c with the batch file 
  11.   cltutsub.bat
  12.   Then compile any of the tutor programs with the batch file
  13.   cltut.bat
  14.   Example: C:>cltutsub
  15.            C:>cltut tut2.c
  16.            to compile this program.
  17.   I compiled and ran all of these on my computer (a 486DX2) and they
  18.   worked for me; that's all I can say!
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <dos.h>
  24. #include <math.h>
  25. #include <conio.h>
  26. #include <graph.h>
  27. #include <bios.h>
  28. #include "tutheadr.h"
  29.  
  30. //DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  31. //Procedure SetUpScreen;
  32. //  This gets our screen ready by setting up the pallette and drawing
  33. //  the lines. 
  34. void SetUpScreen()
  35. {
  36.    int Loop;
  37.  
  38.    // Clear the entire PALL variable to zero: 
  39.    _fmemset(Pall,0,768);
  40.  
  41.  //This sets colors 0 to 200 in the PALL variable to values between
  42.  //0 to 63. the MOD function gives you the remainder of a division,
  43.  //ie. 105 mod 10 = 5:
  44.    for(Loop=0;Loop<200;Loop++) 
  45.        Pall[Loop][0]=(unsigned char)(Loop%64);
  46.  
  47.    for(Loop=0;Loop<320;Loop++)
  48.    {
  49.   // These two lines start drawing lines from the left and the right
  50.   // hand sides of the screen, using colors 1 to 199. Look at these
  51.   // two lines and understand them: 
  52.      Line(319,199,319-Loop,0,(unsigned char)((Loop%199)+1));
  53.      Line(0,0,Loop,199,(unsigned char)((Loop%199)+1));
  54.      PalPlay(1); // This calls the PalPlay procedure with wait for vsync
  55.    }
  56. }
  57.  
  58. //DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  59. void SetUpScreenV2()
  60. {
  61.    int Loop;
  62.  
  63.    _fmemset(Pall,0,768);
  64.  
  65.  //This sets colors 0 to 200 in the PALL variable to values between
  66.  //0 to 63. 
  67.    for(Loop=0;Loop<200;Loop++) 
  68.        Pall[Loop][1]=(unsigned char)(Loop%64);
  69.  
  70.    for(Loop=0;Loop<320;Loop++)
  71.    {
  72.      Line(319,199,319-Loop,0,(unsigned char)(((Loop/2)%199)+1));
  73.      Line(0,0,Loop,199,(unsigned char)(((Loop/2)%199)+1));
  74.    }
  75. }
  76.  
  77. //DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  78. void SetUpScreenV3()
  79. {
  80.    int Loop;
  81.  
  82.    _fmemset(Pall,0,768);
  83.  
  84.  //This sets colors 0 to 200 in the PALL variable to values between
  85.  //0 to 63. 
  86.  //for(Loop=0;Loop<256;Loop++) 
  87.  //    Pall[Loop][2]=(unsigned char)(Loop%64);
  88.    for(Loop=0;Loop<64;Loop++)
  89.        Pall[Loop][0]=(unsigned char)(Loop%64);
  90.    for(Loop=64;Loop<128;Loop++)
  91.        Pall[Loop][1]=(unsigned char)(Loop%64);
  92.    for(Loop=128;Loop<192;Loop++)
  93.    {
  94.        Pall[Loop][0]=(unsigned char)(Loop%64);
  95.        Pall[Loop][2]=(unsigned char)(Loop%64);
  96.    }
  97.    for(Loop=192;Loop<256;Loop++)
  98.        Pall[Loop][2]=(unsigned char)(Loop%64);
  99.  
  100.    for(Loop=0;Loop<320;Loop++)
  101.      Line(Loop,0,319-Loop,199,(unsigned char)(1+(Loop/2)%199));
  102.    for(Loop=1;Loop<199;Loop++)
  103.      Line(0,199-Loop,319,Loop,(unsigned char)(1+((199-Loop)/2)%199));
  104. }
  105.  
  106. // DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  107. // Procedure HiddenScreenSetup;
  108. //  This procedure sets up the screen while it is blacked out, so that the
  109. //  user can"t see what is happening. }
  110. void HiddenScreenSetup()
  111. {
  112.   int loop1,loop2;
  113.   for(loop1=0;loop1<320;loop1++)
  114.      for(loop2=0;loop2<200;loop2++)
  115.        PutPixel(loop1,loop2,(unsigned char)(1+(rand()/128)),VGA);  
  116.        // rand() is in the range 0 to 32767, 2^15 / 2^7 = 2^8 = 256.
  117. }
  118.  
  119.  
  120. void main()
  121. {
  122.   int c;
  123.   _clearscreen(_GCLEARSCREEN);
  124.   printf("This program will draw lines of different colors across the\n");
  125.   printf("screen and change them only by changing their pallette values.\n");
  126.   printf("The nice thing about using the pallette is that one pallette\n");
  127.   printf("change changes the same color over the whole screen, without\n");
  128.   printf("you having to redraw it. Because I am using a WaitRetrace\n");
  129.   printf("command, turning on and off your turbo during the demonstration\n");
  130.   printf("should have no effect.\n");
  131.   printf("\n");
  132.   printf("The second part of the demo blacks out the screen using the\n");
  133.   printf("pallette, fades in the screen, waits for a keypress, then fades\n");
  134.   printf("it out again. I haven't put in any delays for the fadein/out,\n");
  135.   printf("so you will have to put 'em in yourself to get it to the speed you\n");
  136.   printf("like. Have fun and enjoy! ;-)\n");
  137.   printf("\n");
  138.   printf("Hit any key to continue ...\n");
  139.   getch();
  140.   SetMCGA();
  141.   GrabPallette();
  142.   SetUpScreen();
  143.   // Call the PalPlay procedure repeatedly until a key is pressed: 
  144.   // This time without wait for VSync:
  145.   // while(1)
  146.   // {
  147.   //    PalPlay(0);
  148.   //    c=_bios_keybrd(_KEYBRD_READY);
  149.   //    if(c)break;
  150.   // }
  151.   // // Read in the key pressed otherwise it is left in the keyboard buffer }
  152.   // c=_bios_keybrd(_KEYBRD_READ);
  153.   // Call the PalPlay procedure repeatedly until a key is pressed: 
  154.   // This time with wait for VSync:
  155.   while(1)
  156.   {
  157.      PalPlay(1);
  158.      c=_bios_keybrd(_KEYBRD_READY);
  159.      if(c)break;
  160.   }
  161.   // Read in the key pressed otherwise it is left in the keyboard buffer }
  162.   c=_bios_keybrd(_KEYBRD_READ);
  163.   if((c&0xff)==0x71) // 'q'
  164.   {
  165.     RestorePallette();
  166.     SetText();
  167.     return;
  168.   }
  169.   FadeDown();
  170.   SetUpScreenV2();
  171.   while(1)
  172.   {
  173.      PalPlay(1);
  174.      c=_bios_keybrd(_KEYBRD_READY);
  175.      if(c)break;
  176.   }
  177.   c=_bios_keybrd(_KEYBRD_READ);
  178.   if((c&0xff)==0x71)
  179.   {
  180.     RestorePallette();
  181.     SetText();
  182.     return;
  183.   }
  184.   FadeDown();
  185.   SetUpScreenV3();
  186.   while(1)
  187.   {
  188.      PalPlay(1);
  189.      c=_bios_keybrd(_KEYBRD_READY);
  190.      if(c)break;
  191.   }
  192.   c=_bios_keybrd(_KEYBRD_READ);
  193.   if((c&0xff)==0x71)
  194.   {
  195.     RestorePallette();
  196.     SetText();
  197.     return;
  198.   }
  199.   FadeDown();
  200.   /*
  201.   Blackout(); 
  202.   HiddenScreenSetup();
  203.   Blackout();
  204.   FadeUp(2);
  205.   getch();
  206.   FadeDown();
  207.   */
  208.   RestorePallette();
  209.   SetText();
  210.   printf("All done. This concludes the second sample program in the ASPHYXIA\n");
  211.   printf("Training series. You may reach DENTHOR under the name of GRANT\n");
  212.   printf("SMITH on the MailBox BBS, or leave a message to ASPHYXIA on the\n");
  213.   printf("ASPHYXIA BBS. Get the numbers from Roblist, or write to :\n");
  214.   printf("             Grant Smith\n");
  215.   printf("             P.O. Box 270\n");
  216.   printf("             Kloof\n");
  217.   printf("             3640\n");
  218.   printf("I hope to hear from you soon!\n");
  219.   printf("\n"); 
  220.   printf("\n"); 
  221.   printf("     Translated into Microsoft C by: \n");
  222.   printf("        Steve Pinault, 10/06/94,  scp@ohm.att.com  \n");
  223.   printf("\n"); 
  224. }
  225.